<?php
//------------------------------------------------------------------------------
// File view list for Thong tin dau tu
// Modification       :
//------------------------------------------------------------------------------
// Date(yyyy.mm.dd)   Developer                       Action
//------------------------------------------------------------------------------
// 2007.03.15         Oanhhtk                         Created
//------------------------------------------------------------------------------

$ulr = "?".MODUL."=home&".ACTION."=";
global $db, $strtooltip;
include_once(DIR_MODEL."md_san_pham.class.php");
$objSanpham = new MD_Sanpham($db);
$arrayData_Sanpham =  array();
?>
<div id="searchAdvanceForm">
<?
echo "<div class=\"home_slideshow\">
				<iframe src=\"../view/v_home_slideshow.php\" scrolling=\"no\" width=\"758px\" height=\"274px\" frameborder=\"0\" marginheight=\"0\" marginwidth=\"0\"></iframe>
				</div>
				<div style=\"background:url(../images/shadow_slideshow.jpg); height:15px; width:760px; border-top: 1px solid #FF0000;\"></div>";
?>
</div><!-- searchAdvanceForm -->
<div>&nbsp;</div>
<?

					
$arrayData = $objSanpham->getByWhere("*","view_o_trang_chu=1 and hien_thi=1 and gia_sp_km>0","thu_tu asc"); // san pham khuyen mai
V_HomeList($arrayData,1);
$arrayData = $objSanpham->getByWhere("*","view_o_trang_chu=1 and hien_thi=1 and gia_sp_km=0","id desc"); // san pham moi
V_HomeList($arrayData,2);
$arrayData = $objSanpham->getByWhere("*","view_o_trang_chu=1 and hien_thi=1 and solanban>0","solanban desc"); // san pham ban chay
V_HomeList($arrayData,3);

function V_HomeList($arrayData,$flag){
   
	switch($flag)
	{
		case 1:
			$tieude = "SẢN PHẨM KHUYẾN MÃI";
			$div_id = "view_sp_trangchu";
			$height = "320px";
			$next = "next";
			$prev = "prev";
		break;
		case 2:
			$tieude = "SẢN PHẨM MỚI";
			$div_id = "view_sp_trangchu_new";
			$height = "280px";
			$next = "next1";
			$prev = "prev1";
		break;
		default:
			$tieude = "SẢN PHẨM BÁN CHẠY";
			$div_id = "view_sp_trangchu_BC";
			$height = "280px";
			$next = "next2";
			$prev = "prev2";
		break;
	}
	$stt = 1;
	if(!empty($arrayData)){
	?>
	<div id="<?=$div_id?>">
		<p class="title_sp_home"><?=$tieude?></p>
		<div class="bg_l_t">
			<div class="bg_r_t">
				<div class="bg_c_t">
				</div>
			</div>
		</div><!-- bg_l_t -->
		<table cellpadding="0" cellspacing="0" width="100%" class="khung_home" style="padding-left:2px; ">
			<tr>
				<td style="width:37px; " align="center">
					<a href="javascript:void(0)" class="<?=$prev?>">
						<img src="../images/prevew.gif" />
					</a>
				</td>
				
				<td>
					<div style="visibility: visible; overflow: hidden; position: relative; z-index: 2; left: 0px; " 
											class="<?=$div_id?>">
					<ul style="width:692px; ">
					<?
					$stt = 1;
					foreach($arrayData as $row){
					
					$Money = to_money($row['gia_sp']); 
					$money_detail = "$Money VNĐ";
					$Money_new = to_money($row['gia_sp_km']); 
					$money_detail_new = "$Money_new VNĐ";
					$substr=explode(" ",$row['ghi_chu']);
					$text = "<table width='300' cellpadding='0' cellspacing='0'><tr><td>".$row['mo_ta_sp']."</td></tr></table>";
					
					?>
						<li style="width:173px; overflow: hidden; float: left;  ">
							<table width="100%" cellpadding="0" cellspacing="0" border="0" >
								<tr>
									<td valign="top">
										
										<span class="ten_sp">
										<a href="?modul=sanpham&action=View&id_loai_sp=<?=$row['id_loai_sp']?>&id=<?=$row['id']?>"><?=$row['ten_sp']?></a>
										</span><br>
										<span style="text-align:center; display:block">
										<img src="../images/kc-1.png" />
										</span><br />
										<a href="?modul=sanpham&action=View&id_loai_sp=<?=$row['id_loai_sp']?>&id=<?=$row['id']?>">
										<img src="<?=DIR_IMAGES_VIEW.$row['anh_sp']?>" width="127" height="127" style="padding:10px;" title="cssheader=[boxover-cssheader] cssbody=[boxover-cssbody] header=[<?=$row['ten_sp']?>] body=[<?=$text?>]" ><br />
										</a>
										<?
										if($flag==1){
										?>
										<span class="ten_gia">Giá cũ:&nbsp;&nbsp;</span><span class="gia_cu"><?=$money_detail?> </span><br />
										<span class="ten_gia">Chỉ còn:&nbsp;</span><span class="gia_moi"><?=$money_detail_new?> </span><br /><br />
										<span class="title_khuyenmai">KHUYẾN MẠI: </span><? if($row['ghi_chu']!=''){?><span class="khuyenmai"><?=sub_str($row['ghi_chu'],10)?><? if(count($substr)>10){?>...<? }?></span><br /><? }else{?><br><br><br><? }?>
										<?
										}else{
										?>
										<span class="ten_gia" style="vertical-align:bottom; ">Giá: </span><span class="gia_moi" style="vertical-align:bottom; "><?=$money_detail?> </span><br />
										<?
										}
										?>
										<br>
										<span class="chitiet_sp" style="margin-left:36px; display:block; vertical-align:bottom;">
										<a href="?modul=sanpham&action=View&id_loai_sp=<?=$row['id_loai_sp']?>&id=<?=$row['id']?>">Chi tiết</a>
										</span>
										<span class="muangay" style="margin-left:36px; display:block;">
										<a href="?modul=giohang&action=View&id=<?=$row["id"]?>">Mua ngay</a>
										</span> 						
																	
									</td>
									<td align="center">
										
										<img src="../images/kc-2.jpg" width="20px" />		
										
									</td> 
								</tr>
							</table>
						</li>
						<?
							$stt++;
							
						}//end foreach
						
						?>
					</ul>
					</div>
				</td>
				<td style="width:37px; " align="center">
					<a href="javascript:void(0)" class="<?=$next?>">
						<img src="../images/next.gif" />
					</a>
				</td>
			</tr>
		</table>
		<div style="clear:both"></div>
		<div class="bg_l_b">
			<div class="bg_r_b">
				<div class="bg_c_b">
				</div>
			</div>
		</div><!-- bg_l_b -->
		
	</div><!-- view_sp_trangchu -->
	<?
	}//end if	
}

?>
<script type="text/javascript">
	
	var j = jQuery.noConflict();
	j(function() {
		j(".view_sp_trangchu").jCarouselLite({
			btnNext: ".next",
			btnPrev: ".prev",
			//auto: 5000,
			//speed: 500,
			visible: 4,
			scroll: 4
		});
		j(".view_sp_trangchu_new").jCarouselLite({
			btnNext: ".next1",
			btnPrev: ".prev1",
			//auto: 5000,
			//speed: 500,
			visible: 4,
			scroll: 4
		});
		j(".view_sp_trangchu_BC").jCarouselLite({
			btnNext: ".next2",
			btnPrev: ".prev2",
			//auto: 5000,
			//speed: 500,
			visible: 4,
			scroll: 4
		});
	});
</script>